const { db, query } = require("../../db/db");
const moment = require("moment");

function CreateColumns(req, res) {
  let ColumnName = req.body.ColumnName;
  let ColumnIntroduction = req.body.ColumnIntroduction;
  let ColumnsCoverUrl = req.body.ColumnCover;
  let CreateUserId = Number(req.params.username);
  let CreateTime = moment().format("YYYY-MM-DD HH:mm:ss");

  const insert_article =
    "Insert INTO Columns \
  (ColumnsName,ColumnsIntroduction,ColumnsCoverUrl,CreateUserId,CreateTime) \
  values(?,?,?,?,?)";

  db.query(
    insert_article,
    [ColumnName, ColumnIntroduction, ColumnsCoverUrl, CreateUserId, CreateTime],
    (err, results) => {
      if (err) {
        res.send({
          Message: err,
          status: 1,
        });
      }

      res.send({
        status: 0,
      });
    }
  );
}

module.exports = { CreateColumns };
